User-defined
Introduction
Programmers define their own data types based on primitive data types provided by a programming language, or data types that they have defined previously in a program.
These are called user-defined data types. User-defined data types can be divided into non-composite and composite data types.
Non-composite data types
- A non-composite data type can be defined without referencing another data type.
- It can be a primitive type available in a programming language or a user-defined data type.
- Non-composite user-defined data types are usually used for a special purpose.
Composite data types
- A data type that refers to any other data type in its type definition is a composite data type.
- In Chapter 10, the data type for record was introduced as a composite data type because it refers to other data types.
- Other composite data types include sets and classes.
TYPE
TbookRecord
DECLARE title : STRING
DECLARE author : STRING
DECLARE publisher : STRING
DECLARE noPages : STRING
DECLARE fiction : STRING
ENDTYPE
User-defined
User-defined data types can be divided into and data types.
[0/2]
Enumerated data type
- An enumerated data type contains no references to other data types when it is defined.
- In pseudocode, the type definition for an enumerated data type has this structure:
TYPE <identifier> = (value1, value2, value3, ... )
TYPE Tmonth = (January, February, March, April, May, June, July, August, September, October, November, December)
DECLARE thisMonth : Tmonth
DECLARE nextMonth : Tmonth
thisMonth ← January // 1
nextMonth ← thisMonth + 1 // 1 + 1 => 2
User-defined
Which type is the following code?
TYPE TDay = (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)
[0/1]
Pointer data type
- A pointer data type is used to reference a memory location.
- This data type needs to have information about the type of data that will be stored in the memory location.
- In pseudocode the type definition has the following structure, in which
^
shows that the type being declared is a pointer and<Typename>
is the type of data to be found in the memory location, for example INTEGER or REAL, or any user-defined data type.
TYPE <pointer> = ^<Typename>
TYPE TmonthPointer = ^Tmonth
DECLARE monthPointer : TmonthPointer
monthPointer ← ^thisMonth
DECLARE myMonth : Tmonth
myMonth ← monthPointer^
User-defined
Which type is the following code?
TYPE TintPointer = ^INTEGER
[0/1]
Sets
- A set is a given list of unordered elements that can use set theory operations such as intersection and union.
- A set data type includes the type of data in the set. In pseudocode, the type definition has this structure:
TYPE <set-identifier> = SET OF <Basetype>
DEFINE <identifier> (value1, value2, value3, ... ) : <set-identifier>
TYPE Sletter = SET OF CHAR
DEFINE Vowel ('a', 'e', 'i', 'o', 'u') : letters
User-defined
Which type is the following code?
TYPE SNumber = SET OF INTEGER
[0/1]
Classes
- A class is a composite data type that includes variables of given data types and methods (code routines that can be run by an object in that class).
- An object is defined from a given class; several objects can be defined from the same class.
- Classes and objects will be considered in more depth in Chapter 20.
User-defined
A is a composite data type that includes variables of given data types and methods.
[0/1]